package com.huasan.www.demon.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 implements DemonCipher{
	
	public String toMD5(String str) throws NoSuchAlgorithmException{
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(str.getBytes());
		byte[]byteDigest = md.digest();
		int i;
		StringBuffer buf = new StringBuffer("");
		for (int offset = 0; offset < byteDigest.length; offset++) {
			i = byteDigest[offset];
			if (i < 0)
				i += 256;
			if (i < 16)
				buf.append("0");
			buf.append(Integer.toHexString(i));
		}
		return buf.toString();
	}

	public String encrypt(String salt, String strIn) throws Exception {
		return toMD5(strIn + salt);
	}

	public String decrypt(String strIn) throws Exception {
		return null;
	}

	@Override
	public String encrypt(String strIn) throws Exception {
		return toMD5(strIn);
	}

	@Override
	public String decrypt(String key, String strIn) throws Exception {
		return null;
	}
}
